﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xejen.Database.Entities.Auditing
{
    /// <summary>
    /// 表示实体(默认主键类型是<see langword="long"/>)的修改信息
    /// </summary>
    /// <remarks>
    /// 包含修改时间，修改人，主键id
    /// </remarks>    
    [Serializable]
    public abstract class ModifierAuditedEntity : ModifierAuditedEntity<long>, IEntity
    {
        /// <inheritdoc cref="ModifierAuditedEntity"/>
        protected ModifierAuditedEntity() { }
    }

    /// <summary>
    /// 表示实体的修改信息
    /// </summary>
    /// <remarks>
    /// 包含修改时间，修改人主键id
    /// </remarks>
    /// <typeparam name="TPrimaryKey">实体的主键类型</typeparam>
    [Serializable]
    public abstract class ModifierAuditedEntity<TPrimaryKey> : Entity<TPrimaryKey>, IModificationAudited
        where TPrimaryKey : struct
    {
        /// <inheritdoc/>
        [Description("修改人的用户Id")]
        public virtual long? ModifierUserId { get; set; }

        /// <inheritdoc/>
        [Description("修改时间")]
        public virtual DateTime? ModificationTime { get; set; }

        /// <inheritdoc cref="ModifierAuditedEntity{TPrimaryKey}"/>
        protected ModifierAuditedEntity()
        {
            ModificationTime = StandardTime.Now;
        }
    }

    /// <summary>
    /// 表示实体的修改信息
    /// </summary>
    /// <remarks>
    /// 包含修改时间，修改人主键id，修改人信息
    /// </remarks>
    /// <typeparam name="TPrimaryKey">实体的主键类型</typeparam>
    /// <typeparam name="TUser">用户表的类型</typeparam>
    [Serializable]
    public abstract class ModifierAuditedEntity<TPrimaryKey, TUser> : ModifierAuditedEntity<TPrimaryKey>, IModificationAudited<TUser>
        where TPrimaryKey : struct
        where TUser : IEntity
    {
        /// <inheritdoc/>
        [ForeignKey("ModifierUserId")]
        public virtual TUser ModifierUser { get; set; }

        /// <inheritdoc cref="ModifierAuditedEntity{TPrimaryKey, TUser}"/>
        protected ModifierAuditedEntity()
        {

        }
    }
}
